package com.longway.common.handler;

import com.jfinal.handler.Handler;
import com.jfinal.kit.HandlerKit;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


public class DirectoryHandler extends Handler {


	public DirectoryHandler() {
	}

	@Override
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		Map map=request.getParameterMap();  
	    Set keSet=map.entrySet();  
	    for(Iterator itr=keSet.iterator();itr.hasNext();){  
	        Map.Entry me=(Map.Entry)itr.next();  
	        Object ok=me.getKey();  
	        Object ov=me.getValue();  
	        String[] value=new String[1];  
	        if(ov instanceof String[]){  
	            value=(String[])ov;  
	        }else{  
	            value[0]=ov.toString();  
	        }  
	        String paraV = value[0];
	    	if (paraV.indexOf("%homepath%") != -1 || paraV.indexOf("../") != -1 ||paraV.indexOf('~') != -1) {
	    		System.out.println("000000000000000000000000000000000");
	    		System.out.println(target);
				HandlerKit.renderError404(request, response, isHandled);
				return;
			}
	       
	      }
		next.handle(target, request, response, isHandled);
	}
}
